package com.atguigu.lease.web.admin.service.impl;

import com.atguigu.lease.model.entity.FeeKey;
import com.atguigu.lease.model.entity.FeeValue;
import com.atguigu.lease.web.admin.mapper.FeeKeyMapper;
import com.atguigu.lease.web.admin.mapper.FeeValueMapper;
import com.atguigu.lease.web.admin.service.FeeKeyService;
import com.atguigu.lease.web.admin.vo.fee.FeeKeyVo;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.stream.Collectors;

/**
* @author liubo
* @description 针对表【fee_key(杂项费用名称表)】的数据库操作Service实现
* @createDate 2023-07-24 15:48:00
*/
@Service
public class FeeKeyServiceImpl extends ServiceImpl<FeeKeyMapper, FeeKey>
    implements FeeKeyService{

    @Autowired
    private FeeValueMapper feeValueMapper;

    @Override
    public List<FeeKeyVo> getFeeKeyVoList() {
        //FeeKeyVo = FeeKey + List<FeeValue>

        List<FeeKey> feeKeyList = baseMapper.selectList(null);

        return feeKeyList.stream().map(k->{
            //baseMapper.selectList(new LambdaQueryWrapper<FeeKey>().eq(FeeKey::getId,k.getId()))
            List<FeeValue> feeValueList = feeValueMapper.selectList(new LambdaQueryWrapper<FeeValue>().eq(FeeValue::getFeeKeyId, k.getId()));
            FeeKeyVo feeKeyVo = new FeeKeyVo();
            BeanUtils.copyProperties(k,feeKeyVo);
            feeKeyVo.setFeeValueList(feeValueList);
            return feeKeyVo ;
        }).collect(Collectors.toList());
    }
}




